home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / challenge / 12.04-Apr96 / LifeTestCode DR3.sit / Life TestCode DR3 / LifeFile.h < prev    next >
Text File  |  1996-03-30  |  2KB  |  77 lines

  1. /* LifeFile.h    */
  2. /* ©Ludovic Nicolle 1996    */
  3.  
  4. /*
  5. The LifeFile file format is as simpler as possible and follow
  6. the following pattern
  7. The first 4 bytes are a long, numRuns, that defines how many 
  8. LifeRuns are stored in the LifeFile.
  9. After that, there is a LifeRun structure followed by as many
  10. BitMap data as (steps+1), each preceded by a long indicating the
  11. stepvalue.
  12.  
  13. If numRuns is greater than 1, new LifeRuns
  14. are simply appended with their associated data. 
  15.  
  16. To obtain the nth LifeRun in the file, one must go through each
  17. LifeRun to compute the next offset and so on. This is not an 
  18. efficient random access file format, but I don't think this to be
  19. important here.
  20. */
  21.  
  22.  
  23. #pragma options align=power
  24.  
  25. typedef struct{
  26. long    stepvalue;
  27. BitMap    cellsBM;
  28. } BitMapStep, *BitMapStepPtr;
  29.  
  30. typedef struct{
  31. long    stepvalue;
  32. long    bmdata[];    /*the BitMap data itself, as raw data of which
  33.                     size is defined by rowBytes * height */
  34. } bmDataStep, bmDataStepPtr;/*this is only for definition purposes.
  35.                             I don't use this type in the code    */
  36.  
  37. typedef struct{
  38. long    maxGen;            /* Generations to compute    */
  39. short    birthRules;        /* see problem statement    */
  40. short    deathRules;        /* see problem statement    */
  41. long    computedGen;    /* nb of computed generations    */
  42. short    filler1;
  43. short    rbytes;        /*width in bytes of each line of the BitMap*/
  44. Rect    worldSize;        /* Rect enclosing the cells BitMap
  45.         This defines the bounds of each bitmap in the run 
  46.         April challenge statement says topleft= {0, 0}*/
  47. long    steps;        /* nb of steps recorded in this run    */
  48. } LifeRun, *LifeRunPtr;
  49.  
  50.  
  51. #pragma options align=reset
  52.  
  53. #define LifeFileType 'LIFE'
  54. #define MutantLifeCreator    'MULI'
  55. #define kMaxRuns    32    /*Maximum number of runs in a single file*/
  56. #define tooManyRunsErr    3064
  57. #define lifeFileCorruptErr    3065
  58. #define noRunsErr        3066
  59. #define badBitMapSizeErr    3067
  60. #define runAbsentErr    3068
  61. #define stepAbsentErr    3069
  62.  
  63. /* prototypes    */
  64.  
  65. OSErr CreateLifeFile(short *refNum, FSSpec *fileSpec);
  66. OSErr OpenLifeFile(short *refNum, FSSpec *fileSpec);
  67. OSErr CloseLifeFile(short *refNum);
  68.  
  69. OSErr AppendLifeRun(short refNum, LifeRun *theRun);
  70. OSErr SetComputedGen(short refNum, long whichRun, long computedGen);
  71. OSErr AppendLifeWorld(short refNum, BitMapStep *lifeWorld);
  72.  
  73. OSErr GetRunNumber(short refNum, long *outRuns);
  74. OSErr ReadLifeRun(short refNum, LifeRun *theRun, long whichRun);
  75. OSErr ReadLifeWorld(short refNum, BitMapStep *lifeWorld, long whichRun, long step);
  76.  
  77.